package maxinshiSomeipTool20.dataMgr.dataType;

import java.util.ArrayList;
import java.util.List;

import ma.xin.shi.AutorsarCommonUtils;

public class DataTypeEntry {
    private String dataTypeName;          // 数据类型名称
    private String dataType;              // Base / Array / Struct = PRIMITIVE ,  ARRAY, RECORD
    private String category;              // bool, string, value, enum (仅基础类型使用)
    private String baseType;              // uint8, int32, float 等 (仅基础类型使用)
    private String minValuel;             // Primitive Type -> value -> min value input
    private String maxValuel;             // Primitive Type -> value -> max value input
    private String arrayLengthType;       // Fixed / Dynamic (仅数组类型使用)
    private String arrayLengthMin;        // 最小长度 (仅数组类型使用)
    private String arrayLengthMax;        // 最大长度 (仅数组类型使用)
    private String arrayMemberType;       // 数组成员类型 (仅数组类型使用)
    private String stringLengthType;      // 字符串长度类型 [Fixed, Dynamic]
    private int stringMinLength;          // 字符串最小长度
    private int stringMaxLength;          // 字符串最大长度

    private List<String[]> enumMembers;   // {enumName, enumValue} (仅枚举类型使用)
    private List<String[]> structMembers; // {memberName, memberType} (仅结构体类型使用)

    public DataTypeEntry() {
        structMembers = new ArrayList<>();
        enumMembers = new ArrayList<>();
    }

    // Getter and Setter 方法
    public String getDataTypeName() {
        return dataTypeName;
    }

    public void setDataTypeName(String dataTypeName) {
        this.dataTypeName = dataTypeName;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }
    
    public String getDataTypeEx() {
    	switch (this.dataType) {
    	case "Primitive Type":
    		return "APPLICATION-PRIMITIVE-DATA-TYPE";
    	case "Array Type":
    		return "APPLICATION-ARRAY-DATA-TYPE";
    	case "Record Type":
    		return "APPLICATION-RECORD-DATA-TYPE";
    	default:
    		AutorsarCommonUtils.logEx("unkown basic data type: " + this.dataType);
    		return "APPLICATION-PRIMITIVE-DATA-TYPE";
    	}
   }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBaseType() {
        return baseType;
    }

    public void setBaseType(String baseType) {
        this.baseType = baseType;
    }

    public String getMinValue() {
        return minValuel;
    }

    public void setMinValue(String minValuel) {
        this.minValuel = minValuel;
    }
    
    public String getMaxValue() {
        return maxValuel;
    }

    public void setMaxValue(String maxValuel) {
        this.maxValuel = maxValuel;
    }

    public String getArrayLengthType() {
        return arrayLengthType;
    }

    public void setArrayLengthType(String arrayLengthType) {
        this.arrayLengthType = arrayLengthType;
    }

    public String getArrayLengthMin() {
        return arrayLengthMin;
    }

    public void setArrayLengthMin(String arrayLengthMin) {
        this.arrayLengthMin = arrayLengthMin;
    }

    public String getArrayLengthMax() {
        return arrayLengthMax;
    }

    public void setArrayLengthMax(String arrayLengthMax) {
        this.arrayLengthMax = arrayLengthMax;
    }

    public String getArrayMemberType() {
        return arrayMemberType;
    }

    public void setArrayMemberType(String arrayMemberType) {
        this.arrayMemberType = arrayMemberType;
    }
   
    public String getStringLengthType() {
        return stringLengthType;
    }

    public void setStringLengthType(String stringLengthType) {
        this.stringLengthType = stringLengthType;
    }

    public int getStringMinLength() {
        return stringMinLength;
    }

    public void setStringMinLength(int stringMinLength) {
        this.stringMinLength = stringMinLength;
    }

    public int getStringMaxLength() {
        return stringMaxLength;
    }

    public void setStringMaxLength(int stringMaxLength) {
        this.stringMaxLength = stringMaxLength;
    }
    
    public List<String[]> getStructMembers() {
        return structMembers;
    }

    public void addStructMember(String name, String type) {
        String[] member = new String[2];
        member[0] = name;
        member[1] = type;
        structMembers.add(member);
    }

    public void removeStructMember(int index) {
        if (index >= 0 && index < structMembers.size()) {
            structMembers.remove(index);
        }
    }

    // 动态生成索引用于显示
    public List<String[]> getFormattedStructMembers() {
        List<String[]> formattedMembers = new ArrayList<>();
        for (int i = 0; i < structMembers.size(); i++) {
            String[] member = new String[3];
            member[0] = String.valueOf(i + 1); // 自动编号从1开始
            member[1] = structMembers.get(i)[0]; // Member Name
            member[2] = structMembers.get(i)[1]; // Member Type
            formattedMembers.add(member);
        }
        return formattedMembers;
    }
    
 // Getter and Setter for enumMembers
    public List<String[]> getEnumMembers() {
        return enumMembers;
    }

    public void addEnumMember(String name, String value) {
        String[] member = new String[2];
        member[0] = name;
        member[1] = value;
        enumMembers.add(member);
    }

    public void removeEnumMember(int index) {
        if (index >= 0 && index < enumMembers.size()) {
            enumMembers.remove(index);
        }
    }

    // 动态生成索引用于显示（枚举）
    public List<String[]> getFormattedEnumMembers() {
        List<String[]> formattedEnums = new ArrayList<>();
        for (int i = 0; i < enumMembers.size(); i++) {
            String[] item = new String[3];
            item[0] = String.valueOf(i + 1); // 自动编号从1开始
            item[1] = enumMembers.get(i)[0]; // Enum Name
            item[2] = enumMembers.get(i)[1]; // Enum Value
            formattedEnums.add(item);
        }
        return formattedEnums;
    }

}
